﻿using System.Data;
using BookTheBook.Data.NameDefinitions;
using Migrator.Framework;

namespace BookTheBook.Migrations
{
    [Migration(4)]
    public class _004_NewTableCopyOfTheBook : Migration
    {
        public override void Up()
        {
            Database.AddTable(TableNames.Copy,
                                  new Column(ColumnNames.CopyId, DbType.Int32, ColumnProperty.PrimaryKeyWithIdentity),
                                  new Column(ColumnNames.BookId, DbType.Int32, ColumnProperty.NotNull),
                                  new Column(ColumnNames.RentDetailsId, DbType.Int32, ColumnProperty.None));

            Database.AddForeignKey(ForeignKeyNames.BookToCopy,
                                       TableNames.Copy, ColumnNames.BookId,
                                       TableNames.Book, ColumnNames.BookId);

            Database.AddForeignKey(ForeignKeyNames.RentDetailsToCopy,
                                       TableNames.Copy, ColumnNames.RentDetailsId,
                                       TableNames.RentDetails, ColumnNames.RentDetailsId);
        }

        public override void Down()
        {
            Database.RemoveForeignKey(ForeignKeyNames.BookToCopy, TableNames.Copy);
            Database.RemoveForeignKey(ForeignKeyNames.RentDetailsToCopy, TableNames.Copy);
            Database.RemoveTable(TableNames.Copy);
        }
    }
}
